package com.ksd.api.controller;

import com.ksd.api.beans.TvDataResponse;
import com.ksd.api.utils.HttpServletUtil;
import com.ksd.common.core.controller.BaseController;
import com.ksd.common.core.domain.AjaxResult;
import com.ksd.common.enums.UserStatus;
import com.ksd.system.domain.SysMovie;
import com.ksd.system.domain.SysTvData;
import com.ksd.system.domain.SysTvType;
import com.ksd.system.service.ISysMovieService;
import com.ksd.system.service.ISysTvDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
public class GetMovieCategory extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(GetMovieCategory.class);
    @Autowired
    private ISysTvDataService sysTvDataService;
    @Autowired
    private ISysMovieService sysMovieService;

    @RequestMapping(value = "/api/user/vod/getMovieCategory", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult getTvType(HttpServletRequest httpServletRequest) {
        logger.info("===================指定获取电影分类===============");
        HttpServletUtil.getRequestParam(httpServletRequest);
        SysTvData sysTvData = new SysTvData();
        sysTvData.setStatus(UserStatus.OK.getCode());
        sysTvData.setTypeId(Long.valueOf(SysTvType.movieDefaultId));
        List<SysTvData> sysTvDataList = sysTvDataService.selectSysTvDataList(sysTvData);
        List<TvDataResponse> child = new ArrayList<>();
        for (SysTvData tvData : sysTvDataList) {

            SysMovie sysMovie = new SysMovie();
            sysMovie.setTypeData(tvData.getId());
            List<SysMovie> movieList = sysMovieService.selectSysMovieList(sysMovie);

            if (movieList != null && movieList.size() > 0) {
                TvDataResponse tvDataResponse = new TvDataResponse();
                tvDataResponse.setCat_name(tvData.getName());
                tvDataResponse.setCat_id(Integer.valueOf(tvData.getId().toString()));
                tvDataResponse.setParent_id(Integer.valueOf(SysTvType.movieDefaultId));
                tvDataResponse.setPos(Integer.valueOf(tvData.getId().toString()));
                child.add(tvDataResponse);
            }
        }

        return AjaxResult.success(child);
    }
}